const puppeteer = require("puppeteer");
const cheerio = require("cheerio");
var list = async ctx =>{
            /* 1.新建一个浏览器的实例 */
            const browser = await puppeteer.launch({
                headless:false,
                defaultViewport:null
            });
            /* 2.新建一个页面 */
            const page = await browser.newPage();
            /* 3.到达某个页面 */
            await page.goto('https://www.duitang.com/');
            await page.waitForTimeout(3000)
            //获取数据
            let content = await page.content();
            let $ = cheerio.load(content,{
                decodeEntities:false
            })
            let arr=[];
            let images=[];
            $(".dynamic-feed-item").each((index,value)=>{
                var avatar = $(value).find(".avatar").attr("src");
                var username = $(value).find(".user-desc .username").html();
                var label = $(value).find(".dynamic-album-desc").html();
                images=[];
                $(value).find(".dynamic-multi-img-container .dynamic-multi-img").each((index,value)=>{
                    images.push($(value).attr("src"));
                })
                var like = $(value).find(".like-action .detail-text").html();
                var star = $(value).find(".favorite-action .detail-text").html();
                var id = $(value).attr("data-id");
                arr.push({avatar,username,label,images,like,star,id})
            })
            ctx.body = arr;
    
}
module.exports = list;